package org.wyq.myweb.servlet;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.wyq.myweb.config.BeanConfig;
import org.wyq.myweb.jmx.snapshot.ISystemSnapshot;

public class SystemInforServlet extends HttpServlet {

	@Override
	public void init() throws ServletException {
		super.init();
	}

	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
	}

	/**
	 * generated by system
	 */
	private static final long serialVersionUID = 3415826173168330848L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doSnapshot(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doSnapshot(req, resp);
	}
	
	private void doSnapshot(HttpServletRequest req, HttpServletResponse resp) throws IOException{
		resp.setContentType("application/json");
		resp.setCharacterEncoding("UTF-8");
		ISystemSnapshot snapshot = BeanConfig.getBean(ISystemSnapshot.class);
		resp.getWriter().write(snapshot.snapshotJsonString());
	}
	
	
	

}
